var a = require("../../../mybehaviors/location/location"), t = getApp();

Component({
    behaviors: [ a ],
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        U_tabcontrol: {
            type: null
        },
        btnFlag: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        index: {
            type: null
        },
        store_id: {
            type: null
        },
        plugin_active: {
            type: null
        },
        store_alone_temp: {
            type: null
        },
        page_id: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        isLast: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        language: "",
        show_template: "1",
        active: 0,
        cate: [ {
            name: "最新",
            id: -2
        } ],
        cateList: [],
        newClassification: "",
        nearbyClassification: "",
        address: "",
        city: "",
        point: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        getMoreDataType: "newClassification",
        cateMoreData: {},
        loading: !1,
        per_page: 12,
        alreadyHandleArray: [],
        arrIndex: 1,
        allLoaded: !1,
        loadTab: !1
    },
    lifetimes: {
        attached: function() {
            var a = wx.getStorageSync("langIndex");
            this.setData({
                language: a.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), this.data.U_tabcontrol ? Number(this.data.datas.get_number) > 0 && this.getFirstData(this.data.datas.list) : 2 == this.data.datas.get_style ? this.setData({
            cateList: this.data.datas.list,
            isLoadMore: !1,
            allLoaded: !0
        }) : (this.data.datas.show_nearby && (this._getLocation(), this.data.cate.push({
            name: "附近",
            id: -1
        })), this.getHomePageData(this.data.datas.cate), Number(this.data.datas.get_number) > 0 && this.getFirstData(this.data.datas.list)), 
        this.data.datas.show_template && this.setData({
            show_template: this.data.datas.show_template
        }), "1" == this.data.datas.list.micro_style_type && this.setData({
            show_template: "2"
        }), "0" == this.data.datas.list.micro_style_type && this.setData({
            show_template: "1"
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        getHomePageData: function(a) {
            var t = this.data.cate.concat(a);
            this.setData({
                cate: t,
                loadTab: !0
            });
        },
        getFirstData: function(a) {
            a && (this.setData({
                total_page: a.last_page
            }), this.data.page < this.data.total_page ? this.setData({
                isLoadMore: !0
            }) : this.setData({
                isLoadMore: !1,
                allLoaded: !0
            }), a.data.length > this.data.datas.get_number && (a.data.splice(this.data.datas.get_number, a.data.length - this.data.datas.get_number), 
            this.setData({
                isLoadMore: !1,
                allLoaded: !0
            })), this.setData({
                cateList: a.data
            }));
        },
        getClassification: function(a, e, i) {
            var s = this, d = this, n = t.getNetAddresss("plugin.micro-communities.api.index.getStick");
            d.pageInit();
            var r = {};
            Number(this.data.cate[this.data.active].id) > 0 ? r.cat_id = Number(this.data.cate[this.data.active].id) : -2 == Number(this.data.cate[this.data.active].id) ? r.trick_new = 1 : -1 == Number(this.data.cate[this.data.active].id) && (r.lng = this.data.point.lng, 
            r.lat = this.data.point.lat, r.city_name = this.data.city, r.address = this.data.city), 
            this.data.store_id && (r.store_id = this.data.store_id), t._postNetWork({
                url: n,
                showToastIn: !1,
                data: r,
                success: function(a) {
                    var t = a.data;
                    1 == t.result ? (d.data.total_page = t.data.last_page, console.log("show_template===========", s.data.show_template), 
                    t.data.data.length > s.data.datas.get_number && (t.data.data.splice(s.data.datas.get_number, t.data.data.length - s.data.datas.get_number), 
                    s.setData({
                        isLoadMore: !1,
                        allLoaded: !0
                    })), d.setData({
                        cateList: t.data.data
                    }), d.data.page < d.data.total_page && d.setData({
                        isLoadMore: !0,
                        allLoaded: !1
                    })) : wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1500
                    });
                },
                fail: function(a) {}
            });
        },
        getClassificationBtn: function(a) {
            var t = a.detail.index;
            a.detail.title;
            this.setData({
                active: t,
                cateList: []
            }), this.getClassification();
        },
        pageInit: function() {
            this.setData({
                page: 1,
                total_page: 0,
                isLoadMore: !1,
                loading: !1,
                allLoaded: !0
            });
        },
        jumpDetails: function(a) {
            var t = a.currentTarget.dataset.stickid;
            wx.navigateTo({
                url: "/packageC/micro_communities/microCommentDetails/microCommentDetails?stickId=" + t
            });
        },
        getMoreData: function() {
            var a = this, e = this;
            if (this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length >= this.data.per_page) return e.setData({
                cateList: this.data.cateList.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }), void (this.data.datas.get_number && this.data.cateList.length > this.data.datas.get_number && this.setData({
                isLoadMore: !1,
                allLoaded: !0,
                cateList: this.data.cateList.slice(0, this.data.datas.get_number)
            }));
            if (this.setData({
                isLoadMore: !1
            }), e.data.page >= e.data.total_page) return this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && e.setData({
                cateList: this.data.cateList.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }), void (this.data.datas.get_number && this.data.cateList.length > this.data.datas.get_number && this.setData({
                cateList: this.data.cateList.slice(0, this.data.datas.get_number)
            }));
            var i = {};
            -2 == Number(this.data.cate[this.data.active].id) ? i.trick_new = 1 : -1 == Number(this.data.cate[this.data.active].id) ? (i.lng = this.data.point.lng, 
            i.lat = this.data.point.lat, i.city_name = this.data.city, i.address = this.data.city) : i.cat_id = Number(this.data.cate[this.data.active].id), 
            this.data.store_id && (i.store_id = this.data.store_id), this.setData({
                isLoadMore: !1
            });
            var s = t.getNetAddresss("plugin.micro-communities.api.index.getStick");
            1 == this.data.store_alone_temp && (s = t.getNetAddresss("plugin.store-alone-temp.frontend.member.nav-data"), 
            s += "&code=" + e.data.plugin_active), e.data.page = this.data.page + 1, i.page = this.data.page, 
            t._postNetWork({
                url: s,
                showToastIn: !1,
                data: i,
                success: function(t) {
                    var i = t.data;
                    if (1 == i.result) {
                        var s = i.data.data;
                        e.data.page < e.data.total_page && e.setData({
                            isLoadMore: !0
                        }), s.length > e.data.datas.get_number && (s.splice(e.data.datas.get_number, s.length - e.data.datas.get_number), 
                        a.setData({
                            isLoadMore: !1
                        })), e.setData({
                            cateList: e.data.cateList.concat(s)
                        }), e.triggerEvent("setLoadMore", {
                            isLoadMore: e.data.isLoadMore
                        });
                    } else e.data.page = e.data.page - 1, a.setData({
                        isLoadMore: !1
                    });
                },
                fail: function(a) {}
            });
        }
    },
    observers: {
        bottomShowBol: function(a) {
            this.data.U_tabcontrol ? a && this.data.isLast && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
                newClassification: this.data.newClassification.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            }) : a && this.data.bottomShowBolIndex == this.data.index && this.data.isLoadMore ? this.getMoreData() : this.data.page >= this.data.total_page && this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex).length > 0 && this.setData({
                newClassification: this.data.newClassification.concat(this.data.alreadyHandleArray.slice(this.data.per_page * this.data.arrIndex, this.data.per_page * (this.data.arrIndex + 1))),
                arrIndex: this.data.arrIndex + 1
            });
        }
    }
});